#pragma once
#include <deque>
#include <map>
#include <mutex>

using namespace std;

struct Pos
{
	int xCoord;
	int yCoord;
	char id;
};
mutex mtx_gQue;
mutex mtx_pQue;
class Player
{
private:
	char left, right, up, down;
	int id;
	struct Pos pos;
	deque<char> *pQueue;
	deque<Pos> *gQueue;
	
	int size;
public:

	Player()
	{
		id = 0;
		left = 0;
		right = 0;
		up = 0;
		down = 0;
		pos.xCoord = 0;
		pos.yCoord = 0;
	}

	Player(char id, char left, char right, char up, char down, int xPos, int yPos, int size, deque<char> &pQueue, deque<Pos>  &gQueue)
	{
		this->pos.id = id;
		this->left = left;
		this->right = right;
		this->up = up;
		this->down = down;
		this->pos.xCoord = xPos;
		this->pos.yCoord = yPos;
		this->size = size;
		this->pQueue = &pQueue;
		this->gQueue = &gQueue;
		mtx_gQue.lock();
		gQueue.push_back(pos);
		mtx_gQue.unlock();
	}

	~Player()
	{
	}

	void MovePlayer()
	{
		mtx_pQue.lock();
		if (!pQueue->empty())
		{
			char c = pQueue->front();
			pQueue->pop_front();


			if (c == up && pos.yCoord > 0)
				pos.yCoord--;
			else if (c == down && pos.yCoord < size - 1)
				pos.yCoord++;
			else if (c == left && pos.xCoord > 0)
				pos.xCoord--;
			else if (c == right && pos.xCoord < size - 1)
				pos.xCoord++;
			mtx_gQue.lock();
			gQueue->push_back(pos);
			mtx_gQue.unlock();
		}
		
		mtx_pQue.unlock();
	}

	void operator()()
	{
		while (true)
			MovePlayer();
	}
};

